/**
 * 
 */
package cl.webservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

/**
 * @author MariaJose
 *
 */
public class WebserviceUpdateSms {
	private static String METHOD_NAME ;
	private static String NAMESPACE ;
	private static String URL;

	/**
	 * Datos del ws de mi localhost
	 */
	public void coneccionwsPropio(){

		METHOD_NAME = "cambioEstado";
		NAMESPACE = "http://ws.cl/";
		URL = "http://186.10.182.116:8080/AndroidSmsws/services/ActualizacionWs";
		
	}
	/**
	 * datos del ws alojado en el servidor
	 */
	public void coneccionwsServidor(){

		METHOD_NAME = "cambioEstado";
		NAMESPACE = "http://ws.cl/";
		URL = "http://200.13.4.205:8080/AndroidSmsws1/services/ActualizacionWs?wsdl";
	}
	/**
	 * 
	 * @param methodName
	 */

	public String updateSms(String json){
		
		coneccionwsPropio();
		
		String SOAP_ACTION = NAMESPACE + METHOD_NAME;
		
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
      	PropertyInfo SmsAndroid = new PropertyInfo();
      	SmsAndroid.setName("jsonsms");
      	SmsAndroid.setValue(json);
      	SmsAndroid.setType(String.class);
		
      	request.addProperty(SmsAndroid);
		
		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		soapEnvelope.dotNet = true;
		soapEnvelope.implicitTypes =true;
		soapEnvelope.setOutputSoapObject(request);
	
		AndroidHttpTransport aht = new AndroidHttpTransport(URL);
		
		String datosJsonString;
		
		try
		{
			aht.call(SOAP_ACTION, soapEnvelope);
			SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
			datosJsonString =resultString.toString();
			return datosJsonString;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			datosJsonString = "Error Conexion";
			return datosJsonString;
		}

	}
}
